|
|
|
|
|
|
|
for free at http://www.microsoft.com/scripting, you can run VBScript commands from an MS-DOS Prompt window or the Windows Explorer. The VBScript code itself is created in a text editor and stored in a file with a VBS extension. |
|
|
|
|
|
|
|
|
The Windows Scripting Host actually installs two hosts that can run VBScript code: CSCRIPT.EXE, which is designed for use in an MS-DOS Prompt window, and WSCRIPT.EXE, which is designed for execution from Windows. |
|
|
|
|
|
|
|
|
To demonstrate the difference, create a VBS file that uses the WScript.Echo method, as in the following example: |
|
|
|
|
|
|
|
|
WScript.Echo "Hello, world!" |
|
|
|
|
|
|
|
|
Executing the preceding statement with CScript causes "Hello, world!" to be printed in the MS-DOS Prompt window. WScript, on the other hand, presents the text in a message box. |
|
|
|
|
|
|
|
|
The simplest way of executing a script is to supply the script file name as a parameter to either of the preceding executables: |
|
|
|
|
|
|
|
|
CScript.exe d:\scripts\test.vbs |
|
|
|
|
|
|
|
|
You can also just double-click a script file in the Windows Explorer. However, several command-line options are available for the Scripting host, as listed in Table 30.5. These options must be preceded by two forward slashes (//) in the command line. |
|
|
|
|
| Table 30.5 Scripting Host Parameters | | Parameters | Description | | //B and //I | Selects batch or interactive mode. Batch mode does not display any prompts. | | //logo and //nologo | Controls display of Microsoft copyright information. | | //T:nn | Determines a script timeout in seconds. The script is stopped if execution time exceeds the timeout value. | | //H:CScript | Makes CScript the host associated with your script files. | | //H:WScript | Makes WScript the host associated with your script files. | | //S | Saves these options (for the current Windows user only). |
|
|
|
|
|
|
You can also place the options in Table 30.5 in a WSH file. A WSH file is like a PIF file for batch files; it contains the options in INI file format: |
|
|
|
|
|
|
|
|
[ScriptFile]
Path=D:\scripts\test.vbs
[Options]
Timeout=10 |
|
|
|
|
|